//
// Created by 下次一定 on 2021/9/23.
//
/*
 * 多重背包问题
 * */
#include <iostream>
#include <algorithm>

using namespace std;

/*
 * 将 每个商品打包成 成多个商品
 * 1000个物品   才成多个包裹 log2(2000)=12
 * */
const int N = 100;
int n, m;
int f[N][N], s[N], v[N], w[N];
int of[N];


int main() {
    cin >> n >> m;

    int cnt = 0;
    for (int i = 1; i <= n; i++){
        int a,b,s;
        /*价值 体积 数量*/
        cin >> a >> b >> s;
        int k = 1;
        /*打包1,2,4,....2**n  */
        while(k <= s){
            cnt ++ ;
            v[cnt] = a * k;
            w[cnt] = b * k;
            s -= k;
            k *= 2;
        }
        if(s > 0){
            cnt ++ ;
            v[cnt] = a * s;
            w[cnt] = b * s;
        }
    }

    n = cnt;
    for (int i = 1; i <= n; i ++){
        for (int j = m; j >= w[i]; j--){
            of[j] = max(of[j],of[j-w[i]]+v[i]);
        }
    }
    cout << of[m] <<endl;

    /*
    朴素的做法
    for (int i = 1; i <= n; i++) {
        for (int j = 0; j <= m; j++) {
            for (int k = 0; k <= s[i] && k * w[i] <= j; k++) {
                f[i][j] = max(f[i][j], f[i - 1][j - w[i] * k] + v[i] * k);
            }
        }
    }
*/

}